﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Business.ZCH002;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZCH002 : ABasePage
{
    DataTable dtWk = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZCH002";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "调度指示详细管理画面";

            #region
            //清空画面中的输入框
            proc清空_Init("0");

            //总件数
            this.txt总件数.Text = string.Empty;

            //GridView
            //DataTableを作成 
            //DataTable dt = new DataTable();
            //DataRow dr = new DataRow();
            //dt.Rows.Add(dt);

            ////セッションに格納 
            //this.Session.Add("DataTable", dt) ;
            //this.gvDM.DataSource = dt;
            //this.gvDM.DataBind();

            #endregion
        }

        #region
        //数据表清空
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        #endregion

        //autocomplete
        this.txt所用车型.Text = this.hid所用车型.Value;
        this.txt指示状态.Text = this.hid指示状态.Value;
        this.txt车主.Text = this.hid车主.Value;
        this.txt所属区分.Text = this.hid所属区分.Value;
    }

    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }



    protected void btn执行_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //错误信息
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        #endregion

        //处理区分进行确认
        if (this.txt处理区分.Text == string.Empty) //处理区分为空的场合
        {
            this.SetMessage("GTH000", "IGTH000001", MSG_LEVEL.Info);
            this.AddCssClass(this.txt处理区分, CSS_TEXT_ERROR);
            return;
        }
        else if (this.txt处理区分.Text == "1") //处理区分为1(查询)的场合
        {
            #region
            //调度指示号为空时
            if (this.txt调度指示号.Text == string.Empty)
            {
                this.SetMessage("GTH002", "IGTH002002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                return;
            }

            CZCH002 instance = new CZCH002();
            //通过调度指示号进行头部查询
            ZCH002DS.T_DIAODU_HDataTable dtH = instance.GetDIAODU_H(this.txt调度指示号.Text);

            //通过调度指示号进行明细部查询
            ZCH002DS.T_DIAODU_MDataTable dtM = instance.GetDIAODU_M(this.txt调度指示号.Text);
            if (dtH.Count <= 0  || dtM.Count <= 0)
            {
                //查询失败
                this.SetMessage("GTH002", "IGTH002001", MSG_LEVEL.Error);
                this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                this.txt调度指示号.Focus();
                return;
            }
            else if (dtH.Count > 0 || dtM.Count > 0)
            {
                //将T_DIAODU_H的数据反映到输入框中
                #region
                this.SetMessage("GTH002", "IGTH002000", MSG_LEVEL.Info);

                this.txt装货时间_Day.Text = dtH[0].FAHUO_YUDING_DAY.ToString();
                this.txt装货时间_Hour.Text = dtH[0].FAHUO_YUDING_TIME.ToString();

                this.txt所用车型CD.Text = dtH[0].CHELIANG_XINGTAI.ToString();
                this.txt所用车型.Text = dtH[0].CLXT_HANZI.ToString();
                this.txt运费.Text = dtH[0].HETONG_YUNFEI.ToString();

                this.txt指示状态CD.Text = dtH[0].SHIJI_STA.ToString();
                this.txt指示状态.Text = dtH[0].SJZT_HANZI.ToString();

                this.txt车牌号.Text = dtH[0].CHEPAI_NUM.ToString();

                this.txt所属区分CD.Text = dtH[0].SUOSHU_KBN.ToString();
                this.txt所属区分.Text = dtH[0].SSQF_HANZI.ToString();

                this.txt车主CD.Text = dtH[0].CHEZHU.ToString();
                this.txt车主.Text = dtH[0].CHEZHU_NAME.ToString();

                this.txt车主联系电话1.Text = dtH[0].TEL_NUM1.ToString();
                this.txt车主联系电话2.Text = dtH[0].TEL_NUM2.ToString();

                this.txt合同编号.Text = dtH[0].BEIZHU.ToString();

                this.txt调度指示号.Focus();
                #endregion

                //将T_DIAODU_M的数据反映到明细框中
                #region
                int rowid = 0;
                //
                foreach (var dr in dtM)
                {
                    //创建新行
                    TableRow row = new TableRow();
                    if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

                    //选择
                    TableCell cell = GetTableCell(width: 30, rowspan: 1);
                    //
                    CheckBox cb = new CheckBox();
                    cb.ID = "cb" + rowid;
                    //rb.GroupName = "rad";
                    
                    if (rowid == 0) cb.Checked = true;

                    cell.Controls.Add(cb);
                    row.Cells.Add(cell);//插入单元格

                    //子号
                    cell = GetTableCell(width: 70);
                    cell.Text = dr.SUB_NO;
                    row.Cells.Add(cell);

                    //订单号
                    cell = GetTableCell(width: 70);
                    cell.Text = dr.ONO;
                    row.Cells.Add(cell);

                    //品名
                    cell = GetTableCell(width: 70);
                    cell.Text = dr.PINMING_CD + dr.PINM_HANZI;
                    row.Cells.Add(cell);
                    
                    //长
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.LENGTH.ToString();
                    row.Cells.Add(cell);

                    //宽
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.WIDTH.ToString();
                    row.Cells.Add(cell);

                    //高
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.HIGHTH.ToString();
                    row.Cells.Add(cell);

                    //重量
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.WEIGHT.ToString();
                    row.Cells.Add(cell);

                    //数量
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.COUNTS.ToString();
                    row.Cells.Add(cell);

                    //承运费
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.CHENGYUN_COSTS.ToString();
                    row.Cells.Add(cell);

                    //结算方式
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.ZHIFU_TYPE + dr.ZFFS_HANZI;
                    row.Cells.Add(cell);

                    //代理店
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.AGENT + dr.AGENT_HANZI;
                    row.Cells.Add(cell);

                    //发货地
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.ZHUANGHUO + dr.ZHUANGHUO_LUOCHENG;
                    row.Cells.Add(cell);

                    //送货地
                    cell = GetTableCell(width: 170);
                    cell.Text = dr.XIEHUO + dr.XIEHUO_LUOCHENG;
                    row.Cells.Add(cell);
                    
                    
                    this.tblList.Rows.Add(row);


                    rowid++;

                }
                #endregion
            }
            #endregion

        }
        else if (this.txt处理区分.Text == "2") //处理区分为2(登记)的场合
        {
            //登录时，各个控件的属性进行控制
            proc清空_Init(this.txt处理区分.Text);

            #region
            //登记时，各个控件的值进行检查

            //调度指示号的值进行检查
            #region
            if (this.txt调度指示号.Text.Trim() == string.Empty)
            {
                //调度指示号为空的场合,退出登陆
                this.SetMessage("ZCH002", "IZCH002000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                return;
            }
            else
            {
                //对调度指示号进行查询
                CZCH002 instance = new CZCH002();
                //通过调度指示号进行头部查询
                ZCH002DS.T_DIAODU_HDataTable dtH = instance.GetDIAODU_H(this.txt调度指示号.Text);

                //通过调度指示号进行明细部查询
                ZCH002DS.T_DIAODU_MDataTable dtM = instance.GetDIAODU_M(this.txt调度指示号.Text);
                if (dtH.Count > 0 || dtM.Count > 0)
                {
                    //调度指示号已存在场合,退出登陆
                    this.SetMessage("ZCH002", "IZCH002001", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                    this.txt调度指示号.Focus();
                    return;
                }
            }
            #endregion


            //执行登记
            #region
            Boolean isInserted = false;
            CZCH002 instanceH = new CZCH002();
            isInserted = instanceH.InsertT_DIAODU_H(this.txt调度指示号.Text, this.txt车牌号.Text, this.txt所用车型CD.Text, this.txt所属区分CD.Text, this.txt合同编号.Text
                                                 , decimal.Parse(this.txt运费.Text), this.txt车主CD.Text, this.txt车主.Text, this.txt车主联系电话1.Text, this.txt车主联系电话2.Text, this.txt指示状态CD.Text
                                                 , this.txt装货时间_Day.Text, this.txt装货时间_Hour.Text,0,0
                                                 , "CA001"
                                                 , this.txt备注.Text);
            if (!isInserted)
            {
                //登记失败
                this.SetMessage("GTH003", "IGTH003002", MSG_LEVEL.Error);
                this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                this.txt调度指示号.Focus();
            }
            else
            {
                CZCH002 instanceM = new CZCH002();

                string  strDLNO ,strSUB_NO,strONO,strPINMING_CD;
                string  strLENGTH,strWIDTH,strHIGHTH;
                string  strWEIGHT,strCOUNTS,strCHENGYUN_COSTS;
                string  strZHIFU_TYPE,strAGENT,strZHUANGHUO,strXIEHUO;
                int iRowCnt=0;

                strDLNO=this.txt调度指示号.Text.Trim();   //调度指示号

                for (int i = 0; i <= this.gvDM.Rows.Count; i++)
                {
                    //TableRow row = new TableRow();
                    //DataGrid dg = new DataGrid();
                    //row = this.tblList.Rows[0];


                    strSUB_NO = (i + 1).ToString();   //子号
                    strONO = this.gvDM.Rows[i].Cells[0].Text.Trim().ToString();   //订单号
                    strPINMING_CD = this.gvDM.Rows[i].Cells[1].Text.Trim().ToString();   //品名CD
                    strLENGTH = this.gvDM.Rows[i].Cells[3].Text.Trim().ToString();   //长
                    strWIDTH = this.gvDM.Rows[i].Cells[4].Text.Trim().ToString();   //宽
                    strHIGHTH = this.gvDM.Rows[i].Cells[5].Text.Trim().ToString();   //高
                    strWEIGHT = this.gvDM.Rows[i].Cells[6].Text.Trim().ToString();  //总重量
                    strCOUNTS = this.gvDM.Rows[i].Cells[7].Text.Trim().ToString();  //总个数
                    strCHENGYUN_COSTS = this.gvDM.Rows[i].Cells[8].Text.Trim().ToString();   //承运费
                    strZHIFU_TYPE = this.gvDM.Rows[i].Cells[9].Text.Trim().ToString();   //结算方式
                    strAGENT = this.gvDM.Rows[i].Cells[10].Text.Trim().ToString();   //代理店CD
                    strZHUANGHUO = this.gvDM.Rows[i].Cells[12].Text.Trim().ToString();   //装货地CD
                    strXIEHUO = this.gvDM.Rows[i].Cells[14].Text.Trim().ToString();   //卸货地CD


                    isInserted = instanceM.InsertT_DIAODU_M(strDLNO, strSUB_NO, strONO
                                                         , strPINMING_CD, decimal.Parse(strLENGTH), decimal.Parse(strWIDTH), decimal.Parse(strHIGHTH)
                                                         , decimal.Parse(strWEIGHT), decimal.Parse(strCOUNTS), decimal.Parse(strCHENGYUN_COSTS)
                                                         , strZHIFU_TYPE
                                                         , strAGENT, strZHUANGHUO, strXIEHUO
                                                         );

                    if (!isInserted)
                    {

                    }
                    else
                    {
                        //登记成功
                        this.SetMessage("GTH003", "IGTH003000", MSG_LEVEL.Info);
                        this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                        this.txt调度指示号.Focus();
                    }
                }
            }
            #endregion

            #endregion
        }
        else if (this.txt处理区分.Text == "3") //处理区分为1(订正)的场合
        {
            //各种检查
            //??????

            //执行更新
            #region
            Boolean isChanged = false;
            CZCH002 instance = new CZCH002();
            //isChanged = instance.UpdateMChe(this.txt所属区分CD.Text, this.txt车主CD.Text, this.txt主驾驶员CD.Text, this.txt副驾驶员CD.Text
            //                                     , this.txt运输形态CD.Text, "00", this.txt车辆形态CD.Text, this.txt车辆状态CD.Text
            //                                     , decimal.Parse(this.txt可承载重量.Text), decimal.Parse(this.txt车长.Text), decimal.Parse(this.txt车宽.Text)
            //                                     , int.Parse(this.txt使用年数_Year.Text), this.txt年检有效日期_Year.Text
            //                                     , this.txt备注.Text, this.txt调度指示号.Text);
            if (!isChanged)
            {
                //更新失败
                String msg = MessageUtil.GetMessage("GTH001", "IGTH001002");
                lblMsgCD.Text = "IGTH001002";
                lblMsg.Text = msg;
                this.txt处理区分.Focus();
            }
            else
            {
                //更新成功
                String msg = MessageUtil.GetMessage("GTH001", "IGTH001000");
                lblMsgCD.Text = "IGTH001000";
                lblMsg.Text = msg;
                this.txt处理区分.Focus();
            }
            #endregion
        }
        else if (this.txt处理区分.Text == "9") //处理区分为1(删除)的场合
        {
            #region
            //删除时，各个控件的属性进行控制
            proc清空_Init(this.txt处理区分.Text);

            //调度指示号的值进行检查
            #region
            if (this.txt调度指示号.Text.Trim() == string.Empty)
            {
                //调度指示号为空的场合,退出登陆
                this.SetMessage("ZCH002", "IZCH002000", MSG_LEVEL.Error);
                this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                return;
            }
            else
            {
                //对调度指示号进行查询
                CZCH002 instanceSelectDH = new CZCH002();
                ZCH002DS.T_DIAODU_HDataTable dtSelectMChe = instanceSelectDH.GetDIAODU_H(this.txt调度指示号.Text);
                if (dtSelectMChe.Count <= 0)
                {
                    //调度指示号不存在场合,退出登陆
                    this.SetMessage("ZCH002", "IZCH002006", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt调度指示号, CSS_TEXT_ERROR);
                    this.txt调度指示号.Focus();
                    return;
                }
            }
            #endregion

            //执行删除
            Boolean isDeletedDH = false;
            Boolean isDeletedDM = false;
            CZCH002 instance = new CZCH002();
            isDeletedDH = instance.DeleteDiaoDu_H(this.txt调度指示号.Text);
            isDeletedDM = instance.DeleteDiaoDu_M(this.txt调度指示号.Text);
            if (!isDeletedDH || !isDeletedDM )
            {
                //删除失败
                String msg = MessageUtil.GetMessage("GTH004", "IGTH004002");
                lblMsgCD.Text = "IGTH004002";
                lblMsg.Text = msg;
                this.txt调度指示号.Focus();
            }
            else
            {
                //删除成功
                String msg = MessageUtil.GetMessage("GTH004", "IGTH004000");
                lblMsgCD.Text = "IGTH004000";
                lblMsg.Text = msg;
                this.txt调度指示号.Focus();
            }

            #endregion
        }
        else //处理区分为上述以外的场合
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000002");
            lblMsgCD.Text = "IGTH000002";
            lblMsg.Text = msg;
            return;
        }

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";
        //this.SetMessage("", "", MSG_LEVEL.Info);

        //初期化
        if (str处理区分 == "0")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt调度指示号.Enabled = true;
            this.txt装货时间_Day.Enabled = false;
            this.txt装货时间_Hour.Enabled = false;
            this.txt所用车型CD.Enabled = false;

            this.txt运费.Enabled = false;
            this.txt指示状态CD.Enabled = false;
            this.txt车牌号.Enabled = false;
            this.txt所属区分CD.Enabled = false;

            this.txt车主CD.Enabled = false;
            this.txt车主联系电话1.Enabled = false;
            this.txt车主联系电话2.Enabled = false;

            this.txt合同编号.Enabled = false;
            this.txt订单号.Enabled = false;

            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            this.txt处理区分.Text = string.Empty;
            this.txt处理区分.Focus();

            this.txt调度指示号.Text = string.Empty;
            this.txt装货时间_Day.Text = string.Empty;
            this.txt装货时间_Hour.Text = string.Empty;
            this.txt所用车型CD.Text = string.Empty;
            this.txt所用车型.Text = string.Empty;

            this.txt运费.Text = string.Empty;
            this.txt指示状态CD.Text = string.Empty;
            this.txt指示状态.Text = string.Empty;
            this.txt车牌号.Text = string.Empty;
            this.txt所属区分CD.Text = string.Empty;
            this.txt所属区分.Text = string.Empty;

            this.txt车主CD.Text = string.Empty;
            this.txt车主.Text = string.Empty;
            this.txt车主联系电话1.Text = string.Empty;
            this.txt车主联系电话2.Text = string.Empty;

            this.txt合同编号.Text = string.Empty;
            this.txt订单号.Text = string.Empty;

            this.txt备注.Text = string.Empty;
            #endregion
        }

        //查询
        if (str处理区分 == "1")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt调度指示号.Enabled = true;
            this.txt装货时间_Day.Enabled = false;
            this.txt装货时间_Hour.Enabled = false;
            this.txt所用车型CD.Enabled = false;

            this.txt运费.Enabled = false;
            this.txt指示状态CD.Enabled = false;
            this.txt车牌号.Enabled = false;
            this.txt所属区分CD.Enabled = false;

            this.txt车主CD.Enabled = false;
            this.txt车主联系电话1.Enabled = false;
            this.txt车主联系电话2.Enabled = false;

            this.txt合同编号.Enabled = false;
            this.txt订单号.Enabled = false;

            this.txt备注.Enabled = false;
            #endregion

            //控件的Text进行清空
            #region
            //this.txt处理区分.Text = string.Empty;
            this.txt处理区分.Focus();

            this.txt调度指示号.Text = string.Empty;
            this.txt装货时间_Day.Text = string.Empty;
            this.txt装货时间_Hour.Text = string.Empty;
            this.txt所用车型CD.Text = string.Empty;
            this.txt所用车型.Text = string.Empty;

            this.txt运费.Text = string.Empty;
            this.txt指示状态CD.Text = string.Empty;
            this.txt指示状态.Text = string.Empty;
            this.txt车牌号.Text = string.Empty;
            this.txt所属区分CD.Text = string.Empty;
            this.txt所属区分.Text = string.Empty;

            this.txt车主CD.Text = string.Empty;
            this.txt车主.Text = string.Empty;
            this.txt车主联系电话1.Text = string.Empty;
            this.txt车主联系电话2.Text = string.Empty;

            this.txt合同编号.Text = string.Empty;
            this.txt订单号.Text = string.Empty;

            this.txt备注.Text = string.Empty;
            #endregion
        }

        //登记或订正
        if (str处理区分 == "2" || str处理区分 == "3")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt调度指示号.Enabled = true;
            this.txt装货时间_Day.Enabled = true;
            this.txt装货时间_Hour.Enabled = true;
            this.txt所用车型CD.Enabled = true;

            this.txt运费.Enabled = true;
            this.txt指示状态CD.Enabled = true;
            this.txt车牌号.Enabled = true;
            this.txt所属区分CD.Enabled = true;

            this.txt车主CD.Enabled = true;
            this.txt车主联系电话1.Enabled = true;
            this.txt车主联系电话2.Enabled = true;

            this.txt合同编号.Enabled = true;
            this.txt订单号.Enabled = true;

            this.txt备注.Enabled = true;
            #endregion

            //控件的Text不进行清空
            #region

            #endregion
        }

        //删除
        if (str处理区分 == "9")
        {
            //控件的Enabled进行控制
            #region
            this.txt处理区分.Enabled = true;

            this.txt调度指示号.Enabled = true;
            this.txt装货时间_Day.Enabled = false;
            this.txt装货时间_Hour.Enabled = false;
            this.txt所用车型CD.Enabled = false;

            this.txt运费.Enabled = false;
            this.txt指示状态CD.Enabled = false;
            this.txt车牌号.Enabled = false;
            this.txt所属区分CD.Enabled = false;

            this.txt车主CD.Enabled = false;
            this.txt车主联系电话1.Enabled = false;
            this.txt车主联系电话2.Enabled = false;

            this.txt合同编号.Enabled = false;
            this.txt订单号.Enabled = false;

            this.txt备注.Enabled = false;
            #endregion

            //控件的Text不进行清空
            #region

            #endregion
        }
    }

    protected void txt处理区分_TextChange(object sender, EventArgs e)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");

        //处理区分为空的场合
        if (this.txt处理区分.Text == string.Empty)
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000001");
            lblMsgCD.Text = "IGTH000001";
            lblMsg.Text = msg;
            return;
        }
        //处理区分为1,2,3,9的场合
        else if (this.txt处理区分.Text == "1" || this.txt处理区分.Text == "2" ||
            this.txt处理区分.Text == "3" || this.txt处理区分.Text == "9")
        {
            this.proc清空_Init(this.txt处理区分.Text);
        }
        //处理区分为上述以外的场合
        else
        {
            String msg = MessageUtil.GetMessage("GTH000", "IGTH000002");
            lblMsgCD.Text = "IGTH000002";
            lblMsg.Text = msg;
            return;
        }

    }

    protected void btn清除_Click(object sender, EventArgs e)
    {
        //初期化处理
        #region
        //查询时，各个控件的属性进行控制
        proc清空_Init("0");
        #endregion
    }

    protected void  btn订单号追加_Click(object sender, EventArgs e)
    {
        //订单号的值进行检查
        #region
        //订单号的值空的场合，退出登陆
        if (this.txt订单号.Text.Trim() == string.Empty)
        {
            this.SetMessage("ZCH002", "IZCH002000", MSG_LEVEL.Error);
            this.AddCssClass(this.txt订单号, CSS_TEXT_ERROR);
            this.txt订单号.Focus();
            return;
        }
        else
        {
            //对订单号进行查询
            CZCH002 instanceSelectOno = new CZCH002();
            ZCH002DS.T_ORDERDataTable dtSelectOno = instanceSelectOno.GetONO(this.txt订单号.Text);
            //ZCH002DS.T_ORDERRow drSelect = dtSelectOno.Rows;
            if (dtSelectOno.Count <= 0)
            {
                //订单号不存在的场合，退出登陆
                this.SetMessage("ZCH002", "IZCH002001", MSG_LEVEL.Error);
                this.AddCssClass(this.txt订单号, CSS_TEXT_ERROR);
                this.txt订单号.Focus();
                return;
            }
            else
            {
                if (dtSelectOno[0].ORDER_STATUS.ToString()=="02")
                {
                    //订单号完了的场合，退出登陆
                    this.SetMessage("ZCH002", "IZCH002000", MSG_LEVEL.Error);
                    this.AddCssClass(this.txt订单号, CSS_TEXT_ERROR);
                    this.txt订单号.Focus();
                    return;
                }

                DataTable dt = ReadGridView();
                DataRow row = dt.NewRow();
                row.ItemArray = new object[]{
                   "1",
                    (dt.Rows.Count + 1).ToString(),
                    dtSelectOno[0].ONO,
                    dtSelectOno[0].PINMING_CD,dtSelectOno[0].PINM_HANZI,
                    dtSelectOno[0].LENGTH,dtSelectOno[0].WIDTH,dtSelectOno[0].HIGHTH,
                    dtSelectOno[0].WEIGHT,dtSelectOno[0].COUNTS,
                    dtSelectOno[0].CHENGYUN_COSTS,
                    dtSelectOno[0].JIESUAN_TYPE,
                    dtSelectOno[0].AGENT,dtSelectOno[0].AGENT_LUOCHENG,
                    dtSelectOno[0].ZHUANGHUO,dtSelectOno[0].ZHUANGHUO_LUOCHENG,
                    dtSelectOno[0].XIEHUO,dtSelectOno[0].XIEHUO_LUOCHENG,
                    dtSelectOno[0].ORDER_STATUS
                };

                dt.Rows.InsertAt(row, dt.Rows.Count);
                dt.AcceptChanges();
                this.gvDM.DataSource = dt;
                this.gvDM.DataBind();

                #region
                //int rowid = this.tblList.Rows.Count;
                ////
                //foreach (var dr in dtSelectOno)
                //{
                //    //创建新行
                //    TableRow row = new TableRow();
                //    if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

                //    //
                //    TableCell cell = GetTableCell(width: 30, rowspan: 1);
                //    //选择
                //    CheckBox rb = new CheckBox();
                //    rb.ID = "rb" + rowid;
                //    //rb = "rad";
                //    rb.Checked = true;

                //    cell.Controls.Add(rb);
                //    row.Cells.Add(cell);//插入单元格

                //    //指示子号
                //    cell = GetTableCell(width: 50);
                //    cell.Text = rowid.ToString("000");
                //    cell.ID = "sbnum" + rowid;
                //    row.Cells.Add(cell);

                //    //订单号
                //    cell = GetTableCell(width: 60);
                //    cell.Text = dr.ONO;
                //    cell.ID = "ONO" + rowid;
                //    row.Cells.Add(cell);

                //    //品名
                //    cell = GetTableCell(width: 50);
                //    cell.Text = dr.PINMING_CD + dr.PINM_HANZI;
                //    cell.ID = "PINM" + rowid;
                //    row.Cells.Add(cell);

                //    //长
                //    cell = GetTableCell(width: 70);
                //    cell.Text = dr.LENGTH;
                //    row.Cells.Add(cell);

                //    //宽
                //    cell = GetTableCell(width: 100);
                //    cell.Text = dr.WIDTH;
                //    row.Cells.Add(cell);

                //    //高
                //    cell = GetTableCell(width: 100);
                //    cell.Text = dr.HIGHTH;
                //    row.Cells.Add(cell);

                //    //调度指示重量
                //    cell = GetTableCell(width: 65);
                //    cell.Text = dr.FAHUO_WEIGHT.ToString() + "t";
                //    row.Cells.Add(cell);

                //    //调度指示数量
                //    cell = GetTableCell(width: 65);
                //    cell.Text = dr.FAHUO_COUNTS.ToString();
                //    row.Cells.Add(cell);

                //    //承运费
                //    cell = GetTableCell(width: 100);
                //    cell.Text = dr.CHENGYUN_COSTS;
                //    row.Cells.Add(cell);

                //    //结算方式
                //    cell = GetTableCell(width: 100);
                //    cell.Text = dr.JIESUAN_TYPE;
                //    row.Cells.Add(cell);

                //    //代理店
                //    cell = GetTableCell(width: 70);
                //    cell.Text = dr.AGENT + dr.AGENT_LUOCHENG;
                //    row.Cells.Add(cell);

                //    //装货地
                //    cell = GetTableCell(width: 70);
                //    cell.Text = dr.ZHUANGHUO + dr.ZHUANGHUO_LUOCHENG;
                //    row.Cells.Add(cell);

                //    //卸货地
                //    cell = GetTableCell(width: 100);
                //    cell.Text = dr.XIEHUO + dr.XIEHUO_LUOCHENG;
                //    row.Cells.Add(cell);

                //    this.tblList.Rows.Add(row);


                //    rowid++;
                //}
            #endregion

            }
        }
        #endregion
    }

    private DataTable ReadGridView()
    {
        DataTable dt = new DataTable();
        DataRow dr;

        dt.Columns.Add(new DataColumn("选择", typeof(string)));

        dt.Columns.Add(new DataColumn("子号", typeof(string)));
        dt.Columns.Add(new DataColumn("订单号", typeof(string)));
        dt.Columns.Add(new DataColumn("品名CD", typeof(string)));
        dt.Columns.Add(new DataColumn("品名", typeof(string)));
        dt.Columns.Add(new DataColumn("长", typeof(string)));
        dt.Columns.Add(new DataColumn("宽", typeof(string)));
        dt.Columns.Add(new DataColumn("高", typeof(string)));

        dt.Columns.Add(new DataColumn("总重量", typeof(string)));
        dt.Columns.Add(new DataColumn("总个数", typeof(string)));
        dt.Columns.Add(new DataColumn("承运费", typeof(string)));
        dt.Columns.Add(new DataColumn("结算方式", typeof(string)));
        dt.Columns.Add(new DataColumn("代理店CD", typeof(string)));
        dt.Columns.Add(new DataColumn("代理店", typeof(string)));
        dt.Columns.Add(new DataColumn("装货地CD", typeof(string)));
        dt.Columns.Add(new DataColumn("装货地", typeof(string)));

        dt.Columns.Add(new DataColumn("卸货地CD", typeof(string)));
        dt.Columns.Add(new DataColumn("卸货地", typeof(string)));
        dt.Columns.Add(new DataColumn("订单状态", typeof(string)));

        for (int i = 0; i < this.gvDM.Rows.Count; i++)
        {
            dr = dt.NewRow();
            for (int j = 0; j < dt.Columns.Count; j++)
            {
                //if (this.gvDM.Rows[i].Cells[j].Text.Trim() == true)
                //{
                //    dr[j] == "0";
                //}
                //else
                //{
                    dr[j] = this.gvDM.Rows[i].Cells[j].Text.Trim();
                //}
            }
             dt.Rows.Add(dr);
        }
        return dt;
    }


}
